﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class Recherche_correction : Form
    {

        public List<CORRECTION> Recherchecorrection = new List<CORRECTION>();
        
          
        public Recherche_correction()
        {
            InitializeComponent();
            RAMEDEntities1 context = SingletonContext.GetContext();


            
            comboBoxannexe.DataSource = context.Annexe_administratif;
            comboBoxannexe.DisplayMember = "nom_annexe_administratif";
            comboBoxannexe.SelectedItem = null;
            comboBoxresponsable.DataSource = context.Responsables;
            comboBoxresponsable.DisplayMember = "nom_responsable";
            comboBoxresponsable.SelectedItem = null;
            comboBoxtypecorr.DataSource = context.Type_Correction;
            comboBoxtypecorr.DisplayMember = "description";
            comboBoxtypecorr.SelectedItem = null;
          
           
          
    
        }

        

        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBoxdateinf.Checked & checkBoxdatesup.Checked & dateTimePickerdateinf.Value > dateTimePickerdatesup.Value) 
            {
                NotificationTest.NotificationManager nm = new NotificationTest.NotificationManager();
                nm.Show(this, "la date de demande de correction inf doit etré inférieur que la date de demande de correction supp ", Color.Red, 6000);

            }
            RAMEDEntities1 context = SingletonContext.GetContext();
            List<CORRECTION> Lesrecherches = new List<CORRECTION>();
            Lesrecherches = context.CORRECTIONs.ToList<CORRECTION>();

            if (comboBoxresponsable.SelectedItem != null)
            {
                int id_responsable = ((Responsable)comboBoxresponsable.SelectedItem).id_responsable;
                Lesrecherches = Lesrecherches.Where(c => c.id_annexe_administratif == id_responsable).ToList();
            }
            if (comboBoxannexe.SelectedItem != null)
            {
                int id_annexe_administratif = ((Annexe_administratif)comboBoxannexe.SelectedItem).id_annexe_administratif;
                Lesrecherches = Lesrecherches.Where(c => c.id_annexe_administratif == id_annexe_administratif).ToList();
            }
            if (checkBoxdateinf.Checked)
            {
                Lesrecherches = Lesrecherches.Where(c => c.Date_demande_correction.Value.Date >= dateTimePickerdateinf.Value.Date).ToList();
            }
            if (checkBoxdatesup.Checked)
            {
                Lesrecherches = Lesrecherches.Where(c => c.Date_demande_correction.Value <= dateTimePickerdateinf.Value).ToList();
            }


            if (!txtcin.Text.Trim().Equals(""))
            {

                CORRECTION corr = new CORRECTION();
                Lesrecherches = Lesrecherches.Where(p => p.Cin.ToUpper().Equals(txtcin.Text.ToUpper())).ToList<CORRECTION>();

            }
            if (!txtnom.Text.Trim().Equals(""))
            {

                CORRECTION corr = new CORRECTION();
                Lesrecherches = Lesrecherches.Where(p => p.Nom.ToUpper().Equals(txtnom.Text.ToUpper())).ToList<CORRECTION>();

            }
            if (!txtprenom.Text.Trim().Equals(""))
            {

                CORRECTION corr = new CORRECTION();
                Lesrecherches = Lesrecherches.Where(p => p.Prénom.ToUpper().Equals(txtprenom.Text.ToUpper())).ToList<CORRECTION>();

            }

            if (!txtnumero.Text.Trim().Equals(""))
            {
                CORRECTION corr = new CORRECTION();
                int numeroDossierSaisi = utitlitaire.CasterString(txtnumero.Text);
                Lesrecherches = Lesrecherches.Where(p => p.Num_dossier == numeroDossierSaisi).ToList<CORRECTION>();
            }
            if (comboBoxtypecorr.SelectedItem != null)
            {
                Type_Correction Type_Correction = ((Type_Correction)comboBoxtypecorr.SelectedItem);
                //Lesrecherches = Lesrecherches.Where(c => c.Type_correction. == id_Type_Correction).ToList();
            }

            Recherchecorrection = Lesrecherches;
            mettreAjouterFormGridView();

            

        }
        public void mettreAjouterFormGridView()
        {
            dataGridViewrecherchecorrection.DataSource = null;
            remplirDataGridView();
            dataGridViewrecherchecorrection.Update();
            dataGridViewrecherchecorrection.Refresh();
        }

        private void Recherche_correction_Load(object sender, EventArgs e)
        {

        }

        private void dateTimePickerdate_ValueChanged(object sender, EventArgs e)
        {

        }

        private void checkBoxprenom_CheckedChanged(object sender, EventArgs e)
        {

        }
         

            private void checkBoxcin_CheckedChanged(object sender, EventArgs e)
            {

            }

            private void btnmodifier_Click(object sender, EventArgs e)
            {
                if (dataGridViewrecherchecorrection.CurrentRow == null)
                {
                    NotificationTest.NotificationManager nm = new NotificationTest.NotificationManager();
                    nm.Show(this, "Veuillez sélectionner un enregistrement pour le modifier", Color.Red, 3000);
                }
                else
                {
                    RAMEDEntities1 Context = SingletonContext.GetContext();
                    ModifierCorrectionForm mcf = new ModifierCorrectionForm();
                    RAMEDEntities1 context = new RAMEDEntities1();
                    CORRECTION corre = new CORRECTION();
                    corre = ((CORRECTION)dataGridViewrecherchecorrection.CurrentRow.DataBoundItem);
                    mcf.recherchecorrection = this;

                    mcf.corre = corre;
                    mcf.InitialiserChamps();
                    mcf.Show();
                }
            }
            private void devaliderButton_Click(object sender, EventArgs e)
            {
              
            }

            private void devaliderButton_Click_1(object sender, EventArgs e)
            {
                if (dataGridViewrecherchecorrection.CurrentRow == null)
                {
                    NotificationTest.NotificationManager nm = new NotificationTest.NotificationManager();
                    nm.Show(this, "Veuillez sélectionner un enregistrement pour le Devalider", Color.Red, 3000);
                }
                else
                {

                    DemandeDevalidationForm demandeDevalidation = new DemandeDevalidationForm();
                    demandeDevalidation.recherche_correction = this;
                    demandeDevalidation.Correction = ((CORRECTION)dataGridViewrecherchecorrection.CurrentRow.DataBoundItem);
                    demandeDevalidation.remplirChamps();
                    demandeDevalidation.Show();
                }
            }

            private void button2_Click(object sender, EventArgs e)
            {
                this.Dispose();
            }

            private void Button21_Click(object sender, EventArgs e)
            {
                this.WindowState = FormWindowState.Minimized;
            }


            public void remplirDataGridView()
            {
                dataGridViewrecherchecorrection.AutoGenerateColumns = false;
                dataGridViewrecherchecorrection.ColumnCount = 7;
                dataGridViewrecherchecorrection.Columns[0].HeaderText = "Date demande correction";
                dataGridViewrecherchecorrection.Columns[0].DataPropertyName = "Date_demande_correction";

                dataGridViewrecherchecorrection.Columns[1].HeaderText = "Numéro du dossier";
                dataGridViewrecherchecorrection.Columns[1].DataPropertyName = "Num_dossier";

                dataGridViewrecherchecorrection.Columns[2].HeaderText = "Nom";
                dataGridViewrecherchecorrection.Columns[2].DataPropertyName = "Nom";

                dataGridViewrecherchecorrection.Columns[3].HeaderText = "Prénom";
                dataGridViewrecherchecorrection.Columns[3].DataPropertyName = "Prénom";

                dataGridViewrecherchecorrection.Columns[4].HeaderText = "CIN";
                dataGridViewrecherchecorrection.Columns[4].DataPropertyName = "Cin";

                dataGridViewrecherchecorrection.Columns[5].HeaderText = "Annexe";
                dataGridViewrecherchecorrection.Columns[5].DataPropertyName = "Annexe_administratif";

                dataGridViewrecherchecorrection.Columns[6].HeaderText = " type de correction ";
                dataGridViewrecherchecorrection.Columns[6].DataPropertyName = "description";


                dataGridViewrecherchecorrection.DataSource = Recherchecorrection;
            }

            private void groupBox1_Enter(object sender, EventArgs e)
            {

            }

            private void txtnumero_TextChanged(object sender, EventArgs e)
            {

            }

            private void txtnom_TextChanged(object sender, EventArgs e)
            {

            }

            private void button3_Click(object sender, EventArgs e)
            {
               

                
            }

            private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
               
            }

            private void button1_Click_1(object sender, EventArgs e)
            {
                
            }

            private void dataGridViewrecherchecorrection_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {

            }




    }
}
